<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item v-for="(item, index) in breadcrumbs" :key="index">
      <span 
        v-if="index === breadcrumbs.length - 1" 
        class="no-redirect"
      >{{ item.meta?.title }}</span>
      <a 
        v-else 
        class="redirect" 
        @click.prevent="handleLink(item)"
      >{{ item.meta?.title }}</a>
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const breadcrumbs = ref([])

// 获取面包屑数据
const getBreadcrumbs = () => {
  const matched = route.matched.filter(item => item.meta && item.meta.title)
  breadcrumbs.value = matched
}

// 监听路由变化
watch(
  () => route.path,
  () => getBreadcrumbs(),
  { immediate: true }
)

// 处理面包屑点击
const handleLink = (item) => {
  router.push(item.path)
}
</script>

<style scoped>
.redirect {
  color: #666;
  cursor: pointer;
}

.redirect:hover {
  color: #409EFF;
}

.no-redirect {
  color: #97a8be;
  cursor: text;
}
</style> 